package com.ethan.dynamicproxy;

import com.ethan.staticproxy.RealSubject;
import com.ethan.staticproxy.Subject;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

/**
 * @author ethan
 * create 2018-08-02 上午11:10
 * desc 生成动态代理对象的工厂
 **/
public class DynProxyFactory {
    public static Subject getIntance(){
        Subject delete = new RealSubject();
        InvocationHandler handler = new SubjectInvocationHandler(delete);
        Subject proxy =(Subject) Proxy.newProxyInstance(delete.getClass().getClassLoader(),delete.getClass().getInterfaces(),handler);
        return proxy;
    }
}
